<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加-修改</title>
    <link rel="stylesheet" href="../frame/layui/css/layui.css">
    <link rel="stylesheet" href="../frame/static/css/style.css">
    <link rel="icon" href="../frame/static/image/code.png">
</head>
<body class="body">

<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">服务名称</label>

        <div class="layui-input-block">
            <input type="text" name="server" id='server' autocomplete="off" placeholder="请输入标题" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">方法名称</label>

        <div class="layui-input-inline">
            <input type="text" name="method" id='method' lay-verify="required" placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">方法描述</label>

        <div class="layui-input-block">
            <input type="text" name="descript" id='descript' autocomplete="off" placeholder="请输入" 
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">group</label>

        <div class="layui-input-inline">
            <input type="text" name="group" id='group'  placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">version</label>

        <div class="layui-input-inline">
            <input type="text" name="version" id='version'  placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">set</label>

        <div class="layui-input-inline">
            <input type="text" name="set" id='set'  placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
    	<label class="layui-form-label">请求参数</label>
        <div class="layui-input-block">
            <textarea id="request" name='request' placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
    	<label class="layui-form-label">公共参数</label>
        <div class="layui-input-block">
            <textarea id="attachments" name='attachments' placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
    	<label class="layui-form-label">期望返回值</label>
        <div class="layui-input-block">
            <textarea id="response" name ='response' placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="sub">提交</button>
    </div>
     <div class="layui-form-item layui-form-text">
    	<label class="layui-form-label">返回结果</label>
        <div class="layui-input-block">
            <textarea id="realRet" name ='realRet' placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
</form>

<script src="../frame/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
function reset(data) {
	$('#server').val(data.serverName);
	$('#method').val(data.method);
	$.ajax({
        type : "get",  //提交方式  
        url : "/api/service/searchServiceTest",//路径  
        data : {
        	'server':data.serverName,
        	'method':data.method
        },//数据，这里使用的是Json格式进行传输  
        dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
        success : function(result) {//返回数据根据结果进行相应的处理
			if(result.data!=null){
				$('#request').val(result.data.REQUEST);
	        	$('#response').val(result.data.RESPONSE);
	        	$('#attachments').val(result.data.ATTACHMENTS);
	        	$('#descript').val(result.data.DESCRIPT);
			} 
        }  
    }); 
}
    layui.use(['form', 'layedit', 'laydate', 'element'], function () {
        var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , element = layui.element;

        //监听提交
        form.on('submit(sub)', function(data){
        	$.ajax({
	            type : "post",  //提交方式  
	            url : "/api/service/serviceTest",//路径  
	            data : data.field,//数据，这里使用的是Json格式进行传输  
	            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
	            success : function(result) {//返回数据根据结果进行相应的处理  
	            	if(result.code ==0){
	            		if(result.isMatchResult==true){
		            		layer.msg("调用成功，与预期结果匹配");
		            	}else{
		            		layer.msg("调用成功，与预期不匹配");
		            	}
		            	$('#realRet').val(JSON.stringify(result.ret));
	            	}else{
	            		layer.msg("调用失败，请查看服务日志");
	            		$('#realRet').val(JSON.stringify(result.ret));
	            	}
	            },
	            error:function(request){
	            	layer.msg('请求异常');
	            }
	        }); 
            return false;
        });

    });
</script>
</body>
</html>